package com.cookie; /**
 * @author wzm
 * @create 2023-05-10 14:47
 */

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;

@WebServlet("/cookie01")
public class CookieServlet01 extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //1.创建Cookie对象
        Cookie cookie01 = new Cookie("username","zs");//通过构造方法添加保存的值
        Cookie cookie02 = new Cookie("password","123");//通过构造方法添加保存的值

        //2.通知浏览器保存
        response.addCookie(cookie01);

        response.getWriter().write("恭喜，Cookie创建成功了！");
    }
}
